/*
 * This file is part of the Sx Framework Library.
 * 
 * Copyright (C) 2013 University of Colorado Denver
 * <min.choi@ucdenver.edu> <shane.transue@ucdenver.edu>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy 
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 * copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 */
#ifndef SX_MAP_H
#define SX_MAP_H

#include <map>

namespace Sx {
namespace Util {

template <typename Key, typename Value>
class Map {
public:
	typedef std::map<Key, Value> MapType;
	typedef typename MapType::iterator MapIterator;
	typedef typename MapType::const_iterator ConstMapIterator;

	Map();
	virtual ~Map();

	bool isEmpty() const;
	bool contains(const Key& key) const;

	void add(Key key, Value value);
	void put(Key key, Value value);
	bool remove(Key key);
	unsigned int size() const;

	void clear();
	void empty();

	const Value& getValue(Key key);

	MapIterator begin();
	MapIterator end();
	ConstMapIterator begin() const;
	ConstMapIterator end() const;

private:
	MapType imp;
};

template <typename Key, typename Value>
Sx::Util::Map<Key, Value>::Map() {}

template <typename Key, typename Value>
Sx::Util::Map<Key, Value>::~Map() {}

template <typename Key, typename Value>
bool Sx::Util::Map<Key, Value>::isEmpty() const {
	return this->imp.empty();
}

template <typename Key, typename Value>
bool Sx::Util::Map<Key, Value>::contains(const Key& key) const {
	ConstMapIterator i = this->imp.find(key);
	if ( i == this->imp.end() ) return false;
	return true;
}

template <typename Key, typename Value>
void Sx::Util::Map<Key, Value>::add(Key key, Value value) {
	this->imp.insert(std::pair<Key, Value>(key, value));
}

template <typename Key, typename Value>
void Sx::Util::Map<Key, Value>::put(Key key, Value value) {
	this->imp.insert(std::pair<Key, Value>(key, value));
}

template <typename Key, typename Value>
bool Sx::Util::Map<Key, Value>::remove(Key key) {
	this->imp.erase(key);
	return true;
}

template <typename Key, typename Value>
unsigned int Sx::Util::Map<Key, Value>::size() const {
	return this->imp.size();
}

template <typename Key, typename Value>
void Sx::Util::Map<Key, Value>::clear() {
	this->imp.erase(this->imp.begin(), this->imp.end());
}

template <typename Key, typename Value>
void Sx::Util::Map<Key, Value>::empty() {
	this->clear();
}

template <typename Key, typename Value>
const Value& Sx::Util::Map<Key, Value>::getValue(Key key) {
	ConstMapIterator i = this->imp.find(key);
	return i->second;
}

template <typename Key, typename Value>
typename Sx::Util::Map<Key, Value>::MapIterator Sx::Util::Map<Key, Value>::begin() {
	return this->imp.begin();
}

template <typename Key, typename Value>
typename Sx::Util::Map<Key, Value>::MapIterator Sx::Util::Map<Key, Value>::end() {
	return this->imp.end();
}

template <typename Key, typename Value>
typename Sx::Util::Map<Key, Value>::ConstMapIterator Sx::Util::Map<Key, Value>::begin() const {
	return this->imp.begin();
}

template <typename Key, typename Value>
typename Sx::Util::Map<Key, Value>::ConstMapIterator Sx::Util::Map<Key, Value>::end() const {
	return this->imp.end();
}

}

}

#endif
